<template>
    <div id='subPage'>
        <div style="width: 100%;display:flex;justify-content: space-between;align-items: center;margin-bottom: 10px">
            <div class="toBack" @click="$router.push({ path: '/quality/checkTask' })" style="cursor:pointer;"> <span class="el-icon-arrow-left">返回</span></div>
            <div class="operationBox" style="padding: 0;">
                <div class="tableBtn"  @click="addRowFn(1)"  v-if="state == 0 && !isEdit">
                    <div class="btnBox">
                        <div class="text">编辑</div>
                    </div>
                </div>
                <div class="tableBtn"  @click="addRowFn(3)"  v-if="state == 0 && isEdit">
                    <div class="btnBox">
                        <div class="text"> + 分配任务</div>
                    </div>
                </div>
            </div>
        </div>
        <div class="inputName" style="padding:20px;margin-bottom:10px;border-radius: 4px;" v-if="isShow == 1">
            <div class="item">
                <span style="color:#777777;">任务名称：</span>
                <Tooltip  transfer :content="title ? title : '—'" placement="top-start"  max-width='500'>
                    <div class="p" style="overflow: hidden;text-overflow:ellipsis;white-space:nowrap;cursor: pointer;"> {{title ? title : '—'}}</div>
                </Tooltip>
            </div>
            <div class="item">
                <span style="color:#777777;">检查说明：</span>
                <Tooltip  transfer :content="content ? content : '—'" placement="top-start"  max-width='500'>
                    <div class="p" style="overflow: hidden;text-overflow:ellipsis;white-space:nowrap;cursor: pointer;">{{content ? content : '—'}}</div>
                </Tooltip>
            </div>
        </div>
        <div class="inputName" style="padding:20px;margin-bottom:10px;border-radius: 4px;" v-if="state == 0 && isEdit">
            <div class="item">
                <span class="tip">*</span>
                <span style="color:#777777;">任务名称：</span>
                <Input v-model="title" placeholder="请输入" show-word-limit :maxlength="maxlength" style="flex:1;" clearable/>
                <input type="password" autocomplete="new-password" style="display: none" />
            </div>
            <div class="item">
                <span  style="color:#777777;">检查说明：</span>
                <Input v-model="content" placeholder="此地区可能存在隐患问题，需仔细检查" show-word-limit :maxlength="maxlength" style="flex:1;" clearable/>
                <input type="password" autocomplete="new-password" style="display: none" />
            </div>
        </div>
        <div class="bottom">
            <div class="tableBox">
                <div class="tableList" ref="tableList">
                    <el-table :data="taskList" style="width: 100%;border:1px solid #E9F2F6;" :stripe="true">
                        <template slot="empty">
                            <div class="no_lsit" style="width:96%;margin:auto;">
                                <img src="./../../assets/images/common/rotary_nodata.png" alt=""
                                        style="width:3.9rem; height: 2.4rem;">
                            </div>
                        </template>
                        <el-table-column prop="userName" label="检查人" align="center"></el-table-column>
                        <el-table-column prop="checkType" label="检查频率" align="center">
                            <template slot-scope="scope">
                                {{scope.row.checkType == 2 ? '每日检查' : '单次检查'}}
                            </template>
                        </el-table-column>
                        <el-table-column prop="timeList" label="计划检查时间" width="300px" >
                            <template slot-scope="scope">
                                <div v-if="scope.row.checkType == 2">
                                    <Tooltip  transfer :content="scope.row.timeList.length > 0 ? scope.row.timeList.join(',') : '—'" placement="top-start"  max-width='245'>
                                        <div style="width:280px;overflow: hidden;text-overflow:ellipsis;white-space:nowrap;cursor: pointer;">
                                            {{scope.row.timeList.length > 0 ? scope.row.timeList.join(',') : '—'}}
                                        </div>
                                    </Tooltip>
                                </div>
                                <div v-else>
                                    {{scope.row.timeList[0]}}至{{scope.row.timeList[1]}}
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="partArr" label="检查部位"  width="300px">
                            <template slot-scope="scope">
                                <Tooltip  transfer :content="scope.row.partArr.length > 0 ? scope.row.partArr.join(',') : '—'" placement="top-start"  max-width='200'>
                                    <p style="width:280px;overflow: hidden;text-overflow:ellipsis;white-space:nowrap;cursor: pointer;">
                                        {{scope.row.partArr.length > 0 ? scope.row.partArr.join(',') : '—'}}
                                    </p>
                                </Tooltip>
                            </template>
                        </el-table-column>
                        <el-table-column prop="state" label="状态" align="center"  v-if='state !== 0'>
                            <template slot-scope="scope">
                                <div class="p">
                                    <el-tag type="info" size="small" v-if="scope.row.state == 0">未开始</el-tag>
                                    <el-tag size="small" v-if="scope.row.state == 1">进行中</el-tag>
                                    <el-tag type="success" size="small" v-if="scope.row.state == 2">已完成</el-tag>
                                    <p v-if="scope.row.overdue == 1" class="overdueTip">超</p>
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="progress" label="检查进度" align="center"  v-if='state !== 0'></el-table-column>
                        <el-table-column  label="操作" align="center"  width='200px' v-if='state == 0 && isEdit'>
                            <template slot-scope="scope">
                                <el-button style="color:#00ACFB" type="text" size="small" @click.native.prevent="addRowFn(2,scope.$index, taskList)" >编辑</el-button>
                                <el-button style="color:#FF001E" @click.native.prevent="removeFn(scope.$index, taskList,1)" type="text" size="small">删除</el-button>
                            </template>
                        </el-table-column>
                        <el-table-column  label="操作" align="center"  width='200px' v-if='state !== 0'>
                            <template slot-scope="scope">
                                <el-button style="color:#00ACFB" type="text" size="small" @click.native.prevent="addRowFn(4,scope.$index, taskList)" >详情</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
                <div class="clearfix pageFix" v-show="taskList.length > 0">
                    <div class="float-right">
                        <Page v-if="totalCount" style="margin: 20px 0;text-align: center;" :current.sync="current" :total="totalCount" :page-size="pageSize" show-elevator show-total @on-change="pageChange"></Page>
                    </div>
                </div>
                <div class="submitBtn"  v-if="state == 0 && isEdit">
                    <div class="button cancel" @click="cancel(2)">取消编辑</div>
                    <div class="button submit" @click="submitFn" v-preventReClick="1500">提交任务</div>
                </div>
            </div>
        </div>

        <Modal v-model="modal" :title="isAdd ? '分配检查任务' :'编辑检查任务'" width="700px;" :mask-closable="false" class-name="msgModal">
            <div class="tackAdd">
                <div class="list">
                    <div class="item">
                        <i class="tip">*</i>
                        <span class="span">检查人：</span>
                        <Select v-model="userId" style="flex:1;" placeholder="请选择" filterable>
                            <Option
                                v-for="(item , index) in overdueList"
                                :value="item.id"
                                :key="index"
                            >{{item.nickname}}</Option>
                        </Select>
                    </div>
                    <div class="item">
                        <i class="tip">*</i>
                        <span class="span">检查频率：</span>
                        <RadioGroup v-model="checkType" filterable>
                            <Radio label="1">单次检查</Radio>
                            <Radio label="2">每日检查</Radio>
                        </RadioGroup>
                    </div>
                    <div class="item">
                        <i class="tip">*</i>
                        <span class="span">检查时间：</span>
                        <DatePicker :type="checkType == 2 ? 'date' : 'daterange'" :options="options" :multiple ='checkType == 2' :clearable="true" v-model="timeList" v-if="inputShow" format="yyyy-MM-dd" placement="top" transfer  placeholder="请选择日期" :style="[{'width': checkType == 2 ? 'calc(100% - 90px)' : '300px'}]" @on-change="getDateArr" ></DatePicker>
                        <DatePicker :type="checkType == 2 ? 'date' : 'daterange'" format="yyyy-MM-dd" placement="top"  placeholder="请选择日期" v-if="inputShow" style="opacity:0;position: absolute;top:-9999px;width:1px;"></DatePicker>
                        </div>
                    <div class="item">
                        <i class="tip">*</i>
                        <span class="span">检查部位：</span>
                        <treeselect style="flex:1;" :multiple="true" :options="partIdList" :flat="true" :default-expand-level="1"  placeholder="请选择检查部位"  v-model="partIds"/>
                        </div>
                </div>
            </div>
            <div slot="footer">
                <div class="footer">
                    <div class="button cancel" @click="cancel(1)">取消</div>
                    <div class="button submit" @click="submit" v-preventReClick="1500">确定</div>
                </div >
            </div>
        </Modal>

        <Modal v-model="detailsModal" title="检查任务详情" width="1120px;" :mask-closable="false" :footer-hide='true' class-name="msgModal">
            <div class="checkTaskDetails">
                <div class="list">
                    <div class="item">
                        <div class="name">检查总数：</div>
                        <div class="num">{{checkNum}}</div>
                    </div>
                    <div class="item">
                        <div class="name">问题总数：</div>
                        <div class="num">{{issueNum}}</div>
                    </div>
                    <div class="item">
                        <div class="name">排查总数：</div>
                        <div class="num">{{screenNum}}</div>
                    </div>
                    <div class="item">
                        <div class="name">进行中：</div>
                        <div class="num">{{wayNum}}</div>
                    </div>
                </div>
                <div class="tabBox" >
                    <div class="tableList">
                        <el-table :data="taskExecDetailsList" style="width: 100%;border:1px solid #E9F2F6;" height="495px" :stripe="true">
                            <img src="./../../assets/images/common/rotary_nodata.png" alt=""
                                 style="width:3.9rem; height: 2.4rem;">
                            <el-table-column prop="checkUserName" label="检查人" align="center"></el-table-column>
                            <el-table-column prop="checkTime" label="检查时间" align="center">
                                <template slot-scope="scope">
                                    {{scope.row.checkTime ? scope.row.checkTime : '—'}}
                                </template>
                            </el-table-column>
                            <el-table-column prop="partName" label="检查部位" align="center"></el-table-column>
                            <el-table-column prop="state" label="状态" align="center" >
                                <template slot-scope="scope">
                                    <div class="p">
                                        <el-tag type="info" size="small" v-if="scope.row.state == 0">未开始</el-tag>
                                        <el-tag size="small" v-if="scope.row.state == 1">进行中</el-tag>
                                        <el-tag type="success" size="small" v-if="scope.row.state == 2">已完成</el-tag>
                                        <p v-if="scope.row.overdue == 1" class="overdueTip">超</p>
                                    </div>
                                </template>
                            </el-table-column>
                            <el-table-column prop="checkResult" label="检查结果" align="center">
                                <template slot-scope="scope">
                                    {{scope.row.checkResult ? scope.row.checkResult == '隐患问题' ? scope.row.checkResult : '巡检排查' : "—"}}
                                </template>
                            </el-table-column>
                            <el-table-column  label="操作" align="center"  width='200px'>
                                <template slot-scope="scope">
                                    <span v-if="scope.row.state != 2">—</span>
                                    <el-button  v-if="scope.row.state == 2" style="color:#00ACFB" type="text" size="small" @click.native.prevent="addRowFn(5,scope.$index, taskExecDetailsList)" >详情</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </div>
                    <div class="clearfix" v-show="taskExecDetailsList.length > 0" >
                        <div class="float-right">
                            <Page v-if="totalCountExecDetails" style="margin: 20px 0;text-align: center;" :current.sync="currentExecDetails" :total="totalCountExecDetails" :page-size="pageSizeExecDetails" show-elevator show-total @on-change="pageChangeExecDetails"></Page>
                        </div>
                    </div>

                </div>
            </div>
        </Modal>

        <Modal v-model="detailsInfoModal" :title="detailsInfoObj.checkResult == '隐患问题' ? '隐患问题' : '巡检排查'" width="900px;" :mask-closable="false" :footer-hide='true' class-name="msgModal">
            <div class="detailsModal">
                <div class="list">
                    <div class="item" style="margin-bottom:15px;">
                        <div class="left">
                            <span style="width: 90px;">检查人 ：</span>
                            <span>{{detailsInfoObj.checkUserName ? detailsInfoObj.checkUserName : '—'}}</span>
                        </div>
                        <div class="right">
                            <span style="width: 90px;">检查部位 ：</span>
                            <span>{{detailsInfoObj.partName ? detailsInfoObj.partName : '—'}}</span>
                        </div>
                    </div>
                    <div class="item"  style="margin-bottom:15px;">
                        <div class="left">
                            <span style="width: 90px;">检查时间 ：</span>
                            <span>{{detailsInfoObj.checkTime ? detailsInfoObj.checkTime : '—'}}</span>
                        </div>
                        <div class="right">
                            <span style="width: 90px;">检查地点 ：</span>
                            <div class="rightText"  style="max-width:400px">
                                <Tooltip  transfer :content="detailsInfoObj.location ? detailsInfoObj.location : '—'" placement="top-start"  max-width='250'>
                                    <p style="width:250px;overflow: hidden;text-overflow:ellipsis;white-space:nowrap;cursor: pointer;">
                                            {{detailsInfoObj.location ? detailsInfoObj.location : '—'}}
                                    </p>
                                </Tooltip>
                            </div>
                        </div>
                    </div>
                    <div class="item"  style="margin-bottom:15px;">
                        <div class="right " >
                            <span style="white-space:nowrap; width: 90px;">检查说明 ：</span>
                            <div class="rightText"  style="max-width:400px">
                                <Tooltip  transfer :content="detailsInfoObj.checkResult ? detailsInfoObj.checkResult : '—'" placement="top-start"  max-width='250'>
                                    <p style="width:250px;overflow: hidden;text-overflow:ellipsis;white-space:nowrap;cursor: pointer;">
                                            {{detailsInfoObj.checkResult ? detailsInfoObj.checkResult : '—'}}
                                    </p>
                                </Tooltip>
                            </div>
                        </div>
                    </div>
                    <div class="item"  style="margin-bottom:15px;">
                        <div class="right " >
                            <span style="white-space:nowrap; width: 90px;">现场图片 ：</span>
                            <div class="img" v-if='detailsInfoObj.imgUrls&&detailsInfoObj.imgUrls.length > 0'>
                                <el-image style=" width: 77px;height: 77px;margin-right: 50px; margin-bottom: 10px;" :src="item" alt="" v-for="(item,i) in detailsInfoObj.imgUrls" :key="i"  :preview-src-list="detailsInfoObj.imgUrls"></el-image>
                            </div>
                            <div class="img" v-else>—</div>
                        </div>
                    </div>
                </div>
            </div>
            <div slot="footer">
                <div class="footer">
                    <div class="button cancel" @click="cancel(3)">取消</div>
                    <div class="button submit" @click="submit" v-preventReClick="1500">确定</div>
                </div >
            </div>
        </Modal>
    </div>
</template>

<script>
import {treeSort , trans , flatten} from '@/sever/config';
import {initYMD} from '@/sever/utils';
import {getUserList,getQualityPartList ,getQualityTaskAdd ,getQualityTaskDetailsList,getQualityTaskExecDetailsList,getQualityExecNum,getQualityTaskEdit} from '@/api/quality.js'
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
    components: { Treeselect },
    data () {
        return {
            options: {
                disabledDate(date) {
                    return date && date.valueOf() < Date.now() - 86400000;
                }
            },
            btnList:[],//权限数组
            taskList:[],//检查任务数组
            taskExecDetailsList:[],//检查信息数组
            maxlength:25,//输入框最大长度
            limitlength:32,//输入框最大长度
            deptId:"",//项目id
            deptName:"",//项目名称
            totalCount:0,//检查任务数据总数
            pageNum:1,//检查任务数据分页
            pageSize:10,//检查任务数据请求量
            current:1,//检查任务数据当前页
            totalCountExecDetails:0,//检查信息数据总数
            pageNumExecDetails:1,//检查信息数据分页
            pageSizeExecDetails:8,//检查信息数据请求量
            currentExecDetails:1,//检查信息数据当前页
            modal:false,//添加弹框
            inputShow:false,//解决文本框自动填充问题
            detailsModal:false,//详情弹框
            detailsInfoModal:false,//检查信息详情
            isAdd:true,//添加flag
            isEdit:true,//修改flag
            overdueList:[],//检查人数组
            partIdList:[],//树形结构检查部位数组
            flattenList:[],//扁平化检查部位数组
            title:"",//检查任务名称
            content:"",//检查任务说明
            userName:"",//提交表格检查人用户名
            userId:"",//提交表格检查人id
            checkType:"1",//提交表格检查类型
            partIds:[],//提交表格检查部位
            timeList:[],//提交表格时间
            editIdnex :'',//修改某一项的下标
            state:'',//状态
            taskId:'',//检查任务Id
            taskItemId:'',//检查任务项Id
            checkNum:'',//检查总数
            issueNum:'',//问题总数
            screenNum	:'',//排查总数
            wayNum:'',//进行中
            detailsInfoObj:{},//排查信息详情
            isShow:1,//显示文字
        }
    },
    computed: {
        porjectObject() {
            return this.$store.state.porjectObject;
        },
    },
    watch: {
        porjectObject(val, oldVal) {
            if (val.deptId != oldVal.deptId) {
                this.deptId = val.deptId;
                this.editIdnex ='';
                this.isShow =1;
                this.getChecktPartList();
                this.getUserListFn();
            }
        },
    },
    methods: {
        addRowFn(type , index, rows){
            if(type == 1){
                this.isEdit = true;
                this.isShow = 2;
                this.userName = "";
                this.userId = "";
                this.checkType = "1";
                this.timeList = [];
                this.partIds = [];
                this.editIdnex ='';
                this.getDetailsListFn();
            }else if(type == 2 ){
                this.modal = true;
                this.userName = rows[index].userName || rows[index].checkUserName;
                this.userId = rows[index].userId || rows[index].checkUserId;
                this.checkType = String(rows[index].checkType);
                this.timeList = rows[index].timeList;
                this.partIds = rows[index].partIdList;
                this.isAdd = false;
                this.editIdnex = index;
            }else if(type == 3){
                this.isAdd = true;
                this.modal = true;
                this.userName = "";
                this.userId = "";
                this.checkType = "1";
                this.timeList = [];
                this.partIds = [];
                this.editIdnex ='';
            }else if(type == 4){
                this.detailsModal = true;
                this.taskItemId = rows[index].taskItemId;
                this.getQualityTaskExecDetailsListFn();
                this.getQualityExecNumFn();
            }else if(type == 5){
                this.detailsInfoModal = true;
                this.detailsInfoObj = rows[index];
            }
        },
        getDateArr(i,v){
            this.timeList = i;
        },
        // 请求检查任务详情列表带分页
        getQualityTaskDetailsListFn() {
            let params = {
                taskId:this.taskId,
                pageSize:this.pageSize,
                pageNum:this.pageNum,

            };
            getQualityTaskDetailsList(params)
                .then(res => {
                    if (res.code == 200) {
                        this.taskList = res.data.list;
                        this.taskList.forEach(v => {
                            v.partArr = [];
                            v.timeList = [];
                            v.userId = v.checkUserId;
                            v.userName = v.checkUserName;
                            v.times.forEach((item, index) =>{
                                v.timeList.push(item)
                            })
                            v.userName = v.checkUserName;
                            if(v.partList.length > 0 ){
                                v.partList.forEach(item => {
                                    v.partArr.push(item.partName);
                                })
                            }
                        });
                        this.totalCount = res.data.total;
                    } else {
                        this.$Message.warning(res.msg);
                    }
                })
                .catch(error => {
                    console.log(error);
                });
        },
        // 请求检查任务详情列表不带分页
        getDetailsListFn() {
            this.taskList  = [];
            let params = {
                taskId:this.taskId,
            };
            getQualityTaskDetailsList(params)
                .then(res => {
                    if (res.code == 200) {
                        this.taskList = res.data;
                        this.taskList.forEach(v => {
                            v.partArr = [];
                            v.partIdList = [];
                            v.timeList = [];
                            v.userId = v.checkUserId;
                            v.userName = v.checkUserName;
                            v.times.forEach((item, index) =>{
                                v.timeList.push(item)
                            })
                            v.userName = v.checkUserName;
                            if(v.partList.length > 0 ){
                                v.partList.forEach(item => {
                                    v.partArr.push(item.partName);
                                    v.partIdList.push(item.partId);
                                })
                            }
                        });
                        this.totalCount = res.data.total;
                    } else {
                        this.$Message.warning(res.msg);
                    }
                })
                .catch(error => {
                    console.log(error);
                });
        },
        // 检查信息数据
        getQualityExecNumFn() {
            let params = {
                taskItemId:this.taskItemId,
            };
            getQualityExecNum(params)
                .then(res => {
                    if (res.code == 200) {
                        this.checkNum = res.data.checkNum || 0;
                        this.issueNum = res.data.issueNum || 0;
                        this.screenNum	 = res.data.screenNum || 0;
                        this.wayNum = res.data.wayNum || 0;
                    } else {
                        this.$Message.warning(res.msg);
                    }
                })
                .catch(error => {
                    console.log(error);
                });
        },
        // 检查信息详情
        getQualityTaskExecDetailsListFn() {
            let params = {
                taskItemId:this.taskItemId,
                pageSize:this.pageSizeExecDetails,
                pageNum:this.pageNumExecDetails,
            };
            getQualityTaskExecDetailsList(params)
                .then(res => {
                    if (res.code == 200) {
                        this.taskExecDetailsList = res.data.list;
                        this.totalCountExecDetails = res.data.total;
                    } else {
                        this.$Message.warning(res.msg);
                    }
                })
                .catch(error => {
                    console.log(error);
                });
        },
        // 分页请求
        pageChange(index) {
            this.pageNum = index;
            this.getQualityTaskExecDetailsListFn();
        },
        // 检查信息详情分页请求
        pageChangeExecDetails(index) {
            this.pageNumExecDetails = index;
            this.getQualityTaskExecDetailsListFn();
        },
        // 请求检查人列表
        getUserListFn() {
            let params = {
                deptId:this.deptId
            };
            getUserList(params)
                .then(res => {
                    if (res.code == 200) {
                        this.overdueList = res.data;
                    } else {
                        this.$Message.warning(res.msg);
                    }
                })
                .catch(error => {
                    console.log(error);
                });
        },
        //获取检查部位
        getChecktPartList() {
            let params = {
                deptId: this.deptId
            };
            getQualityPartList(params)
                .then(res => {
                    if (res.code == 200) {
                        let arr = res.data.list;
                        this.partIdList = treeSort(trans(arr));
                        let flattenList = JSON.stringify(treeSort(trans(arr)));
                        this.flattenList = flatten(JSON.parse(flattenList));
                    } else {
                        this.$Message.warning(res.msg);
                    }
                })
                .catch(error => {
                    console.log(error);
                });
        },
        // 提交数据到表格
        submit(){
            if(!this.userId){
                this.$Modal.warning({
                    title: "您有必选字段",
                    content: "检查人不能为空"
                });
                return;
            }
            if(this.timeList.length == 0){
                this.$Modal.warning({
                    title: "您有必选字段",
                    content: "检查时间不能为空"
                });
                return;
            }
            if(this.partIds.length == 0){
                this.$Modal.warning({
                    title: "您有必选字段",
                    content: "检查部位不能为空"
                });
                return;
            }
            let partArr = [];
            this.partIds.forEach(v => {
                this.flattenList.forEach(item => {
                    if(v == item.id){
                        partArr.push(item.name);
                    }
                })
            })
            let timeList = [];
            if(this.checkType == 2){
                let timeListArr = [];
                if(this.timeList instanceof Array){
                    timeListArr = this.timeList;
                }else{
                    timeListArr = this.timeList.split(',');
                }
                let timeListArrSort = [];
                timeListArr.forEach(v => {
                    timeListArrSort.push(new Date(v).getTime())
                })
                timeListArrSort = timeListArrSort.sort((a,b)=> {return a-b});
                timeListArrSort.forEach(v => {
                    timeList.push(initYMD(v))
                });
            }else{
                timeList = this.timeList;
            }
            this.overdueList.forEach(v => {
                if(this.userId == v.id){
                    this.userName = v.nickname;
                }
            })
            if(this.isAdd){
                let obj = {
                    userId : this.userId,
                    userName : this.userName,
                    checkType : this.checkType,
                    timeList : timeList,
                    partIdList : this.partIds,
                    partArr : partArr,
                };
                this.taskList.push(obj);
            }else{
                let arr = this.taskList;
                let copyArr = [];
                arr.forEach((v , i )=>{
                    if(i == this.editIdnex){
                        let obj = {
                            userId : this.userId,
                            userName : this.userName,
                            checkType : this.checkType,
                            timeList : timeList,
                            partIdList : this.partIds,
                            partArr : partArr,
                        };
                        copyArr.push(obj);
                    }else{
                        copyArr.push(v);
                    }
                })
                this.taskList = copyArr;
            }
            this.modal = false;
        },
        // 提交数据到数据库
        submitFn(){
            if(!this.title){
                this.$Modal.warning({
                    title: "您有必填字段",
                    content: "检查名称不能为空"
                });
                return;
            }
            if(this.taskList.length > 0 ){
                let params = {
                    taskId : this.taskId,
                    deptId : this.deptId,
                    content : this.content,
                    title : this.title,
                    taskList : this.taskList,
                }
                getQualityTaskEdit(params)
                .then(res => {
                    if (res.code == 200) {
                        this.$router.push({ path: '/quality/checkTask' })
                        this.$Message.success("操作成功");
                    } else {
                        this.$Message.warning(res.msg);
                    }
                })
                .catch(error => {
                    console.log(error);
                });
            }else{
                this.$Modal.warning({
                    title: "提示",
                    content: "请添加分配任务"
                });
                return;
            }
        },
        cancel(i){
            if(i == 1){
                this.modal = false;
            }else if(i == 2){
                this.isEdit = false;
                this.isShow = 1;
                let taskDetailsObj = JSON.parse(localStorage.getItem('taskDetailsObj'));
                this.state = taskDetailsObj.state;
                this.taskId = taskDetailsObj.taskId;
                this.title = taskDetailsObj.title;
                this.content = taskDetailsObj.content;
                this.isEdit = this.state == 0 ? false : true;
                this.getQualityTaskDetailsListFn();
            }else if(i == 3){
                this.detailsModal = false;
            }
        },
        removeFn(index,rows,type) {
            if(type == 1){
                this.taskList.splice(index,1);
            }
        },
    },
    mounted(){
        this.deptId = this.$store.state.porjectObject.deptId;
        this.deptName = this.$store.state.porjectObject.name;
        this.btnList = JSON.parse(localStorage.getItem("arr"));
        this.taskList = [];
        let taskDetailsObj = JSON.parse(localStorage.getItem('taskDetailsObj'));
        this.state = taskDetailsObj.state;
        this.taskId = taskDetailsObj.taskId;
        this.title = taskDetailsObj.title;
        this.content = taskDetailsObj.content;
        this.isEdit = this.state == 0 ? false : true;
        this.getChecktPartList();
        this.getUserListFn();
        this.getQualityTaskDetailsListFn();
        setTimeout(()=>{
            this.inputShow = true;
        },1)
    },
    beforeDestroy(){
        localStorage.removeItem('taskDetailsObj')
    },
}
</script>

<style scoped lang="less">
@import "./../../assets/style/themeBase.less";
@import "./../../assets/style/qualityAndSafety/record.less";
</style>

<style scoped lang='scss'>
@import "./../../assets/style/qualityAndSafety/checktask.scss";
@import "./../../assets/style/qualityAndSafety/modal.scss";
@function pxToRem($val) {
    @return $val/100 + rem;
}
/deep/ .tackAdd{
    .list{
        width: 90%;
        margin: auto;
        .item{
            position: relative;
            display: flex;
            justify-content: flex-start;
            align-items: center;
            margin-bottom: 15px;
            .span{
                width: 90px;
            }
            .tip{
                position: absolute;
                left: -5px;
                top: -5px;
                color: red;
            }
        }
    }
}
/deep/ .checkTaskDetails{
    .list{
        display: flex;
        justify-content: center;
        align-items: center;
        margin-bottom:15px;
        .item{
            display: flex;
            justify-content: flex-start;
            align-items: center;
            .name{
                width: 90px;
                font-size: 14px;
                font-family: Microsoft YaHei;
                color: #666666;
            }
            .num{
                width: 100px;
                color: #00ACFB;
                font-size: 16px;
                font-family: Arial;
                font-weight: bold;
            }
        }
    }
    .tabBox {
        width: 100%;
        margin: 0 auto;
        background-color: #fff;
        border-radius: 10px;
        padding: pxToRem(20) 0;
        padding-top: 0;
        box-sizing: border-box;
        .tableList {
            width: 96%;
            margin: auto;
            .el-table {
                color: #5E5F60;
                font-size: pxToRem(14);
                font-family: Source Han Sans CN;
                thead th {
                    color: #333;
                    font-weight: 400;
                }
            }
            .el-table__empty-text {
                width: 100%;
                .no_lsit {
                    margin: auto;
                    img {
                        width: 600px;
                        height: 450px !important;
                    }
                }
            }
            .el-table__row {
                background-color: #fff;
                color: #666;
                cursor: pointer;
            }
            .el-table--striped .el-table__body tr.el-table__row--striped td {
                background-color: #fff;
                cursor: pointer;
            }
        }
    }
}
</style>
